package com.wms.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wms.vo.UserVo;
import com.wms.domain.User;
import com.wms.dto.UserDto;
import com.wms.mapper.UserMapper;
import com.wms.service.UserService;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
@Builder
public class UserServiceImpl implements UserService {
    private final UserMapper userMapper;

    @Override
    public UserVo list(UserDto queryParam) {
        PageHelper.startPage(queryParam.getPage(), queryParam.getPageSize());
        List<User> page = userMapper.page(queryParam);
        Page<User> p = (Page<User>) page;
        UserVo build = UserVo.builder().total(p.getTotal()).rows(p.getResult()).build();
        return build;
    }

    @Override
    public Integer insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User getInfo(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public Integer update(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public Integer deleteByIds(List<Integer> ids) {
        return userMapper.deleteByIds(ids);
    }
}
